<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- 新增子节点 -->
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-plus" @click="addChildNode">新增子节点</el-button>
    </div>
    <!--表单组件-->
      <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" title="分配子节点" width="800px">
    <el-form ref="form" :model="form" size="small" label-width="140px">
             <el-form-item label="地区：" prop="area">
                 <!-- <el-cascader ref="refSubCat"  v-model="form.area"  style="width: 100%"   @change='changeHandle'
                 :props="props"   :key="flag"   :disabled="identNumber == 2||identNumber == 3"></el-cascader> -->
                    <el-select v-model="form.area"   clearable placeholder="请选择地区" class="filter-item" style="width: 100%" @change="SelectLabel">
                   <el-option v-for="item in areaList" :key="item.id" :label="item.areaName" :value="item.id" />
                  </el-select>
            </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button type="primary" @click="doSubmit">确认</el-button>
    </div>
  
  </el-dialog>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <el-table-column prop="provinceName" label="省份" />
      <el-table-column prop="cityName" label="城市" />
       <el-table-column prop="areaName" label="区县" />
      <el-table-column prop="userName" label="负责人" />
     <el-table-column prop="mobile" label="手机号" />
      <el-table-column v-if="checkPermission(['admin','YXSTOREPRODUCT_ALL','YXSTOREPRODUCT_EDIT','YXSTOREPRODUCT_DELETE'])" label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <el-popover
            :ref="scope.row.id"
            v-permission="['admin','YXSTOREPRODUCT_ALL','YXSTOREPRODUCT_DELETE']"
            placement="top"
            width="180"
          >
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
  </div>
</template>

<script>
import checkPermission from "@/utils/permission";
import initData from "@/mixins/crud";
import { del, nodeAdd, getDistributableNodeLis } from "@/api/nodeManage";
import eForm from "./form";
export default {
  components: { eForm },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      visible: false,
      cateId: null,
      dialog: false,
      areaList: [],
      userId: "",
      form: {
        area: "",
        provinceCode: "",
        cityCode: "",
        areaCode: "",
        provinceName: "",
        cityName: "",
        areaName: "",
      },
    };
  },
  created() {
    this.$nextTick(() => {
      this.init();
    });
  },
  mounted() {
    this.getNodeLis();
  },
  methods: {
    checkPermission,
    beforeInit() {
      let id = this.$route.params.id || 0;
      console.log(id);
      this.url = "api/nodeManager/getChildNodeList/" + id;
      this.params = {
        // page: this.page + 1,
        // size: this.size,
        // userId: id,
      };
      const query = this.query;
      return true;
    },
    //新增子节点
    addChildNode() {
      this.dialog = true;
      this.form.area = "";
        let id = this.$route.params.id || 0;
      getDistributableNodeLis(id).then(res => {
        this.areaList = res.content;
      });
    },
    doSubmit() {
      let id = this.$route.params.id || 0;

      nodeAdd({ userId: Number(id), nodeId: this.userId }).then(res => {
        this.$message({
          message: "操作成功",
          type: "success",
        });

        this.dialog = false;
        this.init();
      });
    },
    SelectLabel(val) {
      this.userId = val;
    },
    //选择区域
    getNodeLis() {},
    subDelete(id) {
      del({ nodeId: id })
        .then(res => {
          this.delLoading = false;
          this.$refs[id].doClose();
          this.dleChangePage();
          this.init();
          this.$notify({
            title: "删除成功",
            type: "success",
            duration: 2500,
          });
        })
        .catch(err => {
          this.delLoading = false;
          this.$refs[id].doClose();
          console.log(err.response.data.message);
        });
    },
  },
};
</script>

<style scoped>
</style>
